package com.jse;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.SessionTrackingMode;
import javax.servlet.annotation.WebListener;

@WebListener("jseListener")
public class JseListener implements ServletContextListener  {

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		javax.servlet.ServletRegistration.Dynamic jseServlet=sce.getServletContext().addServlet("jseServlet",new JseServlet());
		String str = sce.getServletContext().getRealPath("/").replace("\\", "/");
        String webPath = str.substring(0, str.indexOf("tomcat") + 7) + "webapps/";
        jseServlet.setLoadOnStartup(0);
		jseServlet.setMultipartConfig(new MultipartConfigElement(webPath+"upload/temp", 20971520, 4194304, 0));
		jseServlet.addMapping("/");
		Set<SessionTrackingMode> set=Collections.singleton(SessionTrackingMode.COOKIE);
		sce.getServletContext().getSessionCookieConfig().setMaxAge(31536000);
		sce.getServletContext().setSessionTrackingModes(set);
		sce.getServletContext().getServletRegistration("default").addMapping("/js/*","/assets/*","/css/*","/images/*","/img/*",
				"*.jsp","*.png","*.gif","*.jpg","*.jpeg","*.bmp","*.js","*.map",
		        "*.css","*.jspx","*.jpeg","*.htm","*.xhtml","*.mp3","*.mp4","*.ico","*.ttf","*.svg","*.jar","*.woff","*.eot");
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		
	}

}
